﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Data.Entity;
using OdeToFood.Models;

namespace OdeToFood
{    
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Cocina", // Route name
                "cocina/{name}", // URL with parameters                
                new { controller = "Cocina", action = "Search", name = UrlParameter.Optional } // Parameter defaults                
            );


            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

        }

        protected void Application_Start()
        {
            Database.SetInitializer(new OdeToFoodDBInitializer());
            

            AreaRegistration.RegisterAllAreas();
            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    }

    public class OdeToFoodDBInitializer : DropCreateDatabaseIfModelChanges<OdeToFoodDB>
    {
        protected override void Seed(OdeToFoodDB context)
        {
            base.Seed(context);
            context.Restaurants.Add(new Restaurant 
            {
                Name = "Pizza x Metro",
                Address = new Address 
                {
                    street = "Urquiza 789",
                    city = "Bahia Blanca",
                    state = "Bs As",
                    country = "Argentina"
                }
            });

            context.Restaurants.Add(new Restaurant 
            {
                Name = "Bambu Dogs in Freezer",
                Address = new Address 
                {
                    street = "Chiclana 425",
                    city = "Bahia Blanca",
                    state = "Bs As",
                    country = "Argentina"
                }
            });

            context.Restaurants.Add(new Restaurant
            {
                Name = "Zottovento Resto Bar",
                Address = new Address
                {
                    street = "Alem 417",
                    city = "Bahia Blanca",
                    state = "Bs As",
                    country = "Argentina"
                }
            });

            context.Restaurants.Add(new Restaurant
            {
                Name = "El cotolengo loco",
                Address = new Address
                {
                    street = "Sixto Laspiur 147",
                    city = "Buenos Aires",
                    state = "Bs As",
                    country = "Argentina"
                }
            });

            context.SaveChanges();

            /*Datos de Reviews */
            context.Reviews.Add(new Review
            {           
                DiningDate = DateTime.Parse("2013-01-02 0:00:00Z"),
                Restaurant = context.Restaurants.First(),                                
                Rating = 7,
                Body = "Con medio metro me hinche lo suficiente",                
            });

            context.Reviews.Add(new Review
            {
                DiningDate = DateTime.Parse("2013-01-12 7:34:42Z"),
                Restaurant = context.Restaurants.First(),                                
                Rating = 10,
                Body = "Comi pizza hasta reventar! muy recomendable!",                
            });

            context.Reviews.Add(new Review
            {
                DiningDate = DateTime.Parse("2013-01-20 7:34:42Z"),
                Restaurant = context.Restaurants.First(),                                      
                Rating = 10,
                Body = "a fantastic culinary dog in the meter",                
            });

            context.SaveChanges();
        }
    
    }

}